<?php
include(dirname(__FILE__).'/../../bootstrap/Doctrine.php');
 
$t = new lime_test(3);
$t->comment('->getTitleSlug()');
$article = Doctrine_Core::getTable('BlogArticle')->createQuery()->fetchOne();
$t->is($article->getTitleSlug(), Blog::slugify($article->getTitle()), '->getTitleSlug() return the slug for the title');
$t->comment('->save()');
$article = create_article();
$article->save();
$isActivated = 'true';
$t->is($article->getIsActivated(), $isActivated, '->save() updates is_activated if not true');
 
$article = create_article(array('is_activated' => 'false'));
$jarticle->save();
$t->is($article->getIsActivated(), 'false', '->save() does not update is_activated if false');
 
function create_article($defaults = array())
{
  static $category = null;
  
  
 
  if (is_null($category))
  {
    $category = Doctrine_Core::getTable('BlogCategory')
      ->createQuery()
      ->limit(1)
      ->fetchOne();
  }
  
  static $user = null;
  
  if (is_null($user))
  {
    $user = Doctrine_Core::getTable('BlogUser')
      ->createQuery()
      ->limit(1)
      ->fetchOne();
  }
 
  $article = new BlogArticle();
  $article->fromArray(array_merge(array(
    'category_id'  => $category->getId(),
    'user_id'  => $user->getId(),
    'title'     => 'Article test',
    'logo'     => 'blabla',
    'content'  => 'Testing is fun',
    'url'        => 'test/article',
    'email'        => 'test@testeur.com',
    'token'        => rand(1111, 9999),
    'is_activated' => true,
  ), $defaults));
 
  return $article;
}


?>
